package org.karelun.whiteboard.ui.actions;

import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
import org.karelun.whiteboard.gef.ui.actions.ActionBarContributor;
import org.karelun.whiteboard.gef.ui.actions.retarget.CopyRetargetAction;
import org.karelun.whiteboard.gef.ui.actions.retarget.CutRetargetAction;
import org.karelun.whiteboard.gef.ui.actions.retarget.DeleteRetargetAction;
import org.karelun.whiteboard.gef.ui.actions.retarget.PasteRetargetAction;
import org.karelun.whiteboard.gef.ui.actions.retarget.RedoRetargetAction;
import org.karelun.whiteboard.gef.ui.actions.retarget.UndoRetargetAction;

/**
 * @Author: KarelunHuang
 * @Date: Jan 23, 2013
 **/
public class WhiteboardEditorActionBarContributor extends ActionBarContributor{

	@Override
	protected void createActions() {
		addRetargetAction(new UndoRetargetAction());
		addRetargetAction(new RedoRetargetAction());
		addRetargetAction(new CopyRetargetAction());
		addRetargetAction(new CutRetargetAction());
		addRetargetAction(new PasteRetargetAction());
		addRetargetAction(new DeleteRetargetAction());
	}

	@Override
	protected void declareGlobalActionKeys() {
	}
	
	@Override
	public void contributeToMenu(IMenuManager menuManager) {
		String editMenuId = "org.karelun.whiteboard.ui.edit.menu";
		IMenuManager editMenuMgr = menuManager.findMenuUsingPath(editMenuId);
		IWorkbenchAction undoAction = ActionFactory.UNDO.create(getWorkbenchWindow());
		editMenuMgr.add(new ActionContributionItem(undoAction));
		IWorkbenchAction redoAction = ActionFactory.REDO.create(getWorkbenchWindow());
		editMenuMgr.add(new ActionContributionItem(redoAction));
		editMenuMgr.add(new Separator());
		IWorkbenchAction copyAction = ActionFactory.COPY.create(getWorkbenchWindow());
		editMenuMgr.add(new ActionContributionItem(copyAction));
		IWorkbenchAction cutAction = ActionFactory.CUT.create(getWorkbenchWindow());
		editMenuMgr.add(new ActionContributionItem(cutAction));
		IWorkbenchAction pasteAction = ActionFactory.PASTE.create(getWorkbenchWindow());
		editMenuMgr.add(new ActionContributionItem(pasteAction));
		editMenuMgr.add(new Separator());
		IWorkbenchAction deleteAction = ActionFactory.DELETE.create(getWorkbenchWindow());
		editMenuMgr.add(new ActionContributionItem(deleteAction));
	}
	
	private IWorkbenchWindow getWorkbenchWindow(){
		return getPage().getWorkbenchWindow();
	}
	
	@Override
	public void contributeToToolBar(IToolBarManager toolBarManager) {
		toolBarManager.add(getAction(ActionFactory.UNDO.getId()));
		toolBarManager.add(getAction(ActionFactory.REDO.getId()));
		toolBarManager.add(new Separator());
		toolBarManager.add(getAction(ActionFactory.COPY.getId()));
		toolBarManager.add(getAction(ActionFactory.CUT.getId()));
		toolBarManager.add(getAction(ActionFactory.PASTE.getId()));
		toolBarManager.add(getAction(ActionFactory.DELETE.getId()));
		toolBarManager.add(new Separator());
	}
}
